﻿using AutoMapper;
using Domain.Flow;
using MediatR;
using U.B.ErrorCode;
using U.B.Repistory;
using U.B.WriteApi.Command.RabbitBWss;

namespace U.B.WriteApi.CommandHander.RabbitBWDD
{
    public class UpdateFarmCommmandHander : IRequestHandler<UpdateFarmCommmand, ApiResult<object>>
    {
        public readonly IMapper _mapper;
        public readonly IRepistory<Farm> _farmRepository;

        public UpdateFarmCommmandHander(IMapper mapper, IRepistory<Farm> farmRepository)
        {
            _mapper = mapper;
            _farmRepository = farmRepository;
        }
        public Task<ApiResult<object>> Handle(UpdateFarmCommmand request, CancellationToken cancellationToken)
        {
            ApiResult<object> apiResult = new ApiResult<object>();
            var farm = _mapper.Map<Farm>(request);
            var result = _farmRepository.Update(farm);
            apiResult.Data = result;
            apiResult.code = Renum.修改成功;
            apiResult.Message = Renum.修改成功.ToString();
            return Task.FromResult(apiResult);

            
        }
    }
}
